home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / kriegspi / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-30  |  2.9 KB  |  134 lines

  1. /* Kriegspiel written by David Wolfe based on a program by Bert Enderton
  2.     May 5, 1986
  3.  
  4.     Network interface modified by Steve Schoch <schoch@ames.arpa>
  5. */
  6.  
  7. #ifndef lint
  8. static char rcsid[] = "$Header: main.c,v 1.3 87/05/19 17:23:17 schoch Exp $";
  9. #endif
  10.  
  11. /* main.c */
  12. #include "externs.h"
  13. #include <ctype.h>
  14. #include <signal.h>
  15. #include <strings.h>
  16.  
  17. char symbol [7] = { '-', 'P', 'K', 'N', 'B', 'R', 'Q' };
  18. u_char whose [100];
  19. u_char occupant [100];
  20. char *colorname [2] = { "white", "black" };
  21. int pawndir [2] = { -10, 10 };
  22.  
  23. LIST        dirlist [7];
  24. LIST        piecelocs [2];
  25. int        kingloc [2];
  26. MOVELIST    movelist = (MOVELIST) NULL;
  27. u_char        ourcolor = UNSET;
  28. u_char        theircolor;
  29. int        lastmovefrom = 0;
  30. int        lastmoveto = 0;
  31. u_char        virgin [100];
  32. bool        drawok [2] = { FALSE, FALSE};
  33. bool        resign = FALSE;
  34. bool        dead = FALSE;
  35. u_char        color=WHITE, state=PLAYING;
  36. u_char        option [NOPTIONS];
  37. WINDOW        *blanksq [89];
  38. WINDOW        *square [89];
  39. WINDOW        *win [23];
  40. WINDOW        *backupwin [23];
  41. WINDOW        *backupscreen;
  42. WINDOW        *blankscreen;
  43. char        sqcolor [2];
  44. bool        vtterm;
  45. bool        dumbterm = FALSE;
  46. bool        reversescr;
  47. int        sqheight;
  48. int        sqwidth;
  49. bool        reverse = FALSE;
  50. bool        iamserver = UNSET;
  51. FILE        *inp, *out;
  52. long        random();
  53.  
  54. main (argc, argv, envp)
  55.     int argc;
  56.     char **argv, **envp;
  57. {
  58.     int i, j, port = 0, trap_sigint();
  59.     char *p, *malloc ();
  60.     long time ();
  61.  
  62.     signal (SIGINT, SIG_IGN);
  63.     signal (SIGPIPE, SIG_IGN);
  64.     srandom (time((long *) NULL));
  65.     if (!strcmp (argv [1], "help")) {
  66.         execle(PRINT_FILE, PRINT_FILE,
  67.                HELP_FILE, 0, envp);
  68.         perror ("execle");
  69.         exit (1);
  70.     }
  71.     if (argc <= 1) {
  72.         printf ("Usage: %s [-bwcaprsdh] user\n", argv[0]);
  73.         printf ("Or for help: %s help\n", argv[0]);
  74.         exit (0);
  75.     }
  76.     for (i = 0; i < NOPTIONS; i++)
  77.         option [i] = UNSET;
  78.     j = 0;
  79.     for (i = 1; i < argc - 1; i++) {
  80.         j = TRUE;
  81.         for (p = argv [i]; *p != '\000'; p++) {
  82.             if isupper (*p)
  83.                 *p = tolower (*p);
  84.             if (*p == '-')
  85.                 j = FALSE;
  86.             else if (*p == 'b')
  87.                 option [COLOR] = BLACK;
  88.             else if (*p == 'w')
  89.                 option [COLOR] = WHITE;
  90.             else if (*p == 'c')
  91.                 option [COLOR] = RANDOM;
  92.             else if (*p == 'a')
  93.                 option [ANNOUNCETAKES] = j;
  94.             else if (*p == 'p')
  95.                 option [ANNOUNCEPAWNS] = j;
  96.             else if (*p == 'r')
  97.                 reverse = TRUE;
  98.             else if (*p == 's')
  99.                 iamserver = j;
  100.             else if (*p == 'd')
  101.                 dumbterm = j;
  102.             else if (isdigit (*p))
  103.                 port = port * 10 + (*p - '0');
  104.             else if (*p == 'h') {
  105.                 execle(PRINT_FILE, PRINT_FILE,
  106.                        HELP_FILE, 0, envp);
  107.                 perror ("execle");
  108.                 exit (1);
  109.             }
  110.         }
  111.     }
  112.     initdirlists ();
  113.     initpiecelocs ();
  114.     initscreen ();
  115.     refresh();
  116.     redraw();
  117.     signal (SIGINT, trap_sigint);
  118.     p = argv [argc - 1];
  119.     message("Connecting...", MESSAGE);
  120.     refresh ();
  121.     connectport (p, port);
  122.     mclear(MESSAGE);
  123.     message("type help for\nsample commands", MESSAGE);
  124.     refresh ();
  125.     dooptions();
  126.     if (ourcolor == WHITE) {
  127.         message("--- WHITE ---", MYCOLOR);
  128.         reverse = 0;
  129.     } else
  130.         message("--- BLACK ---", MYCOLOR);
  131.     initboard (FALSE);
  132.     movecycle ();
  133. }
  134.